package com.himore.api.web.controller.modules;

import java.util.List;

import com.himore.api.common.annotation.Log;
import com.himore.api.common.core.controller.BaseController;
import com.himore.api.common.core.domain.AjaxResult;
import com.himore.api.common.core.domain.entity.SysUser;
import com.himore.api.common.core.page.TableDataInfo;
import com.himore.api.common.enums.BusinessType;
import com.himore.api.common.utils.SecurityUtils;
import com.himore.api.common.utils.poi.ExcelUtil;
import com.himore.api.web.model.UserComplaints;
import com.himore.api.web.service.IUserComplaintsService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 吐槽信息Controller
 * 
 * @author dongwang
 * @date 2020-12-29
 */
@RestController
@RequestMapping("/system/complaints")
public class UserComplaintsController extends BaseController
{
    @Autowired
    private IUserComplaintsService userComplaintsService;

    /**
     * 查询吐槽信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(UserComplaints userComplaints){
        startPage();
        List<UserComplaints> list = userComplaintsService.selectUserComplaintsList(userComplaints);
        return getDataTable(list);
    }

    /**
     * 导出吐槽信息列表
     */
    @Log(title = "吐槽信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(UserComplaints userComplaints){
        List<UserComplaints> list = userComplaintsService.selectUserComplaintsList(userComplaints);
        ExcelUtil<UserComplaints> util = new ExcelUtil<UserComplaints>(UserComplaints.class);
        return util.exportExcel(list, "complaints");
    }

    /**
     * 获取吐槽信息详细信息
     */
    @GetMapping(value = "/{complaintsId}")
    public AjaxResult getInfo(@PathVariable("complaintsId") Long complaintsId){
        return AjaxResult.success(userComplaintsService.selectUserComplaintsById(complaintsId));
    }

    /**
     * 新增吐槽信息
     */
    @Log(title = "吐槽信息", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public AjaxResult add(@RequestBody UserComplaints userComplaints){
        SysUser user = SecurityUtils.getLoginUser().getUser();
        userComplaints.setUserId(user.getUserId());
        return toAjax(userComplaintsService.insertUserComplaints(userComplaints));
    }

    /**
     * 修改吐槽信息
     */
    @Log(title = "吐槽信息", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/edit")
    public AjaxResult edit(@RequestBody UserComplaints userComplaints){
        return toAjax(userComplaintsService.updateUserComplaints(userComplaints));
    }

    /**
     * 删除吐槽信息
     */
    @Log(title = "吐槽信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{complaintsIds}")
    public AjaxResult remove(@PathVariable Long[] complaintsIds){
        return toAjax(userComplaintsService.deleteUserComplaintsByIds(complaintsIds));
    }
}
